// mircoApp/cloud_shop/full_Return_Details/full_Return_Details.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoData: [],
    nowTime: "",
    goodList: [],
    rankList: [],
    // 活动商品最后页数
    goodPage: {
      page: 1,
      total_page: 0
    },
    rankPage: {
      page: 1,
      total_page: 0
    },
    time: 30 * 60 * 60 * 1000,
    timeData: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
      nowTime: Date.parse(new Date()) / 1000
    })
    this.getData();
  },
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  tolink(e) {
    let {
      key,
      params
    } = e.currentTarget.dataset;
    console.log(key, params)
    wx.navigateTo({
      url: `${key}${params}`,
    })
  },
  async getData() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(
        "plugin.cloud-shop.frontend.activity.detail"
      ),
      data: {
        id: this.options.id,
      },
    });
    if (data.result) {
      wx.setNavigationBarTitle({
        title: data.data.name,
      })
      if (data.data.type == 2) {
        this.getRank();
      }
      this.getGoodList();
      this.setData({
        infoData: data.data
      })
    } else {
      app.tips(data.msg);
    }
    console.log(data)
  },
  async getRank() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(
        "plugin.cloud-shop.frontend.activity.rankList"
      ),
      data: {
        id: this.options.id,
      },
    });
    if (data.result) {
      this.setData({
        rankList: data.data.data,
        'rankPage.total_page': data.data.last_page
      })
    } else {
      app.tips(data.msg)
    }
  },
  async getGoodList() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(
        "plugin.cloud-shop.frontend.activity.goodsList"
      ),
      data: {
        id: this.options.id,
      },
    });
    if (data.result) {
      this.setData({
        goodList: data.data.data,
        'goodPage.total_page': data.data.last_page
      })
    } else {
      app.tips(data.msg)
    }
  }
})